package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.text.Annotation;

public class ReflectDemo11 {
    public static void main(String[] args)throws Exception {
        Class<?> cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();
        if(cls.isAnnotationPresent(AutoRunClass.class)) {
            Method method = cls.getDeclaredMethod("sayHello");
            AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
            int value = arm.value();
            System.out.println(value);
            if(value > 0){
                for (int i = 0; i < value; i++){
                    method.invoke(o);
                }
            }
        }else {
            System.out.println("该类没有被AutoRunClass注解");
        }
    }
}
